<template>
  <div class="content">
    <p class="title">{{title}}</p>
    <div v-html="content"></div>
  </div>
</template>

<script>
import { bannerDetail, newsDetail } from '@/api/api';
export default {
  props: {},
  data () {
    return {
      content: '',
      title: ''
    };
  },
  computed: {},
  created () {},
  mounted () {
    console.log('showDetail', this.$mp.query);
    Object.assign(this.$data, this.$options.data());
    this.showDetail(this.$mp.query.classifyId, this.$mp.query.type);
  },
  watch: {},
  methods: {
    // 根据type判断是banner详情还是资讯详情并调对应接口
    showDetail (id, type) {
      if (type === 'banner') {
        this.getBannerDetail(id);
      } else {
        this.getNewsDetail(id);
      }
    },
    // 获取banner详情信息
    async getBannerDetail (id) {
      wx.showLoading({
        title: '加载中',
        icon: 'none',
        duration: 1000
      });
      await bannerDetail(id).then(res => {
        // wx.hideLoading();
        console.log('1111111111111111', res.content);
        this.content = res.content;
        this.title = res.name;
      });
    },
    // 获取资讯列表详情信息
    async getNewsDetail (id) {
      wx.showLoading({
        title: '加载中',
        icon: 'none',
        duration: 1000
      });
      await newsDetail(id).then(res => {
        // wx.hideLoading();
        console.log('getNewsDetail', res.content);
        this.content = res.content;
        this.title = res.name;
      });
    }
  },
  components: {}
};
</script>

<style scoped lang="less">
.title {
  text-align: center;
  padding: 20px 0;
  font-size: 16px;
  color: #333;
  font-weight: bold;
}
.content {
  margin: 0 15px 15px;
  font-size: 14px;
}
</style>
